﻿//********************************************************************************//
//创建日期：<创建日期，2018-3-28>
//创建作者：<郭登杰>
//功能说明：来函水表信息列表(用于水资源销户水表显示)
//********************************************************************************//
using BLL.Access;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL;
using DevExpress.Web;

namespace Web.Controls
{
    public partial class UCLHShuiBiaoListView : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        /// 记录查询结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        /// <summary>
        /// 来函流程步骤
        /// </summary>
        public eLaiHanLCBH LaiHanLC
        {
            get
            {
                return ViewState["LaiHanLC"] == null ? eLaiHanLCBH.未登记 : (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), Convert.ToString(ViewState["LaiHanLC"]));
            }
            set
            {
                ViewState["LaiHanLC"] = value.ToString();
            }
        }


        /// <summary>
        /// 设置列表高度
        /// </summary>
        public int ListHeight
        {
            set
            {
                this.gvList.Settings.VerticalScrollableHeight = value;
            }
        }

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
            this.gvList.Columns[2].Caption = BusinessTool.WType == 1 ? "取水口号" : "井号";
        }

        /// <summary>
        ///重新绑定
        /// </summary>
        public void BindData()
        {
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 清空数据
        /// </summary>
        public void ClearInfo()
        {
            this.dtSource = null;
            this.gvList.DataSource = null;
            this.gvList.DataBind();
        }

        /// <summary>
        /// 根据来函加载信息
        /// </summary>
        /// <param name="laihanxx"></param>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0)
            {
                this.LaiHanLC = eLaiHanLCBH.未登记;
                if (this.LaiHanLX == eLaiHanLX.水资源销户)
                {
                    this.dtSource = new SpHelper().P_QS_SHUIBIAOXXHQ(BusinessTool.WType, laihanxx.S_YONGHUBH).Tables[0];
                    this.BindData();
                }
            }
            else
            {
                if (this.LaiHanLX == eLaiHanLX.水资源销户)
                {
                    this.LaiHanLC = (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
                    this.dtSource = new QS_LH_XIAOHUSBXXProcess().SelectQS_LH_XIAOHUSBXXesDynamic("S_LAIHANBH='" + laihanxx.S_LAIHANBH + "'", null);
                    this.BindData();
                }
            }
        }

        public void CreateShengQingXX(YS_LH_LAIHANXX laihanxx)
        {
            if (this.LaiHanLX == eLaiHanLX.水资源销户)
            {
                //先清除
                QS_LH_XIAOHUSBXXProcess bllT2 = new QS_LH_XIAOHUSBXXProcess();
                bllT2.DeleteQS_LH_XIAOHUSBXXesDynamic("S_LAIHANBH=" + laihanxx.S_LAIHANBH);
                //添加
                foreach (DataRow row in this.dtSource.Rows)
                {
                    QS_LH_XIAOHUSBXX item = new QS_LH_XIAOHUSBXX();
                    item.S_LAIHANBH = laihanxx.S_LAIHANBH;
                    item.S_SHUIBIAOBH = Convert.ToString(row["S_SHUIBIAOBH"]);
                    item.S_QUSHUIKH = Convert.ToString(row["S_QUSHUIKH"]);
                    bllT2.InsertOrUpdate(item);
                }
            }
        }

        #endregion
        public ValidateRS Validate()
        {
            throw new NotImplementedException();
        }
    }
}